import simplejson as sjson
import datetime

UTC_OFFSET = -25200

class user:
    def __init__(self, jason):
        decoder = sjson.JSONDecoder()
        self.json = decoder.decode(jason)
        jason = self.json
        try:
            self.timestamp = datetime.datetime.now()
            self.id = jason['id']
            self.screen_name = jason['screen_name']
            self.followers = float(jason['followers_count'])
            self.followees = float(jason['friends_count'])
            self.recent_status = jason['status']['text']
            self.status_time = datetime.datetime.strptime(jason['status']['created_at'], "%a %b %d %H:%M:%S +0000 %Y") + datetime.timedelta(seconds=UTC_OFFSET)
            self.status_count = jason['statuses_count']
            self.status_age = self.status_time - self.timestamp
            if (self.followers != 0):
                self.quality = self.followers / self.followees
            else:
                self.quality = self.followers / 0.001
        except:
            self.timestamp = datetime.datetime.now()
            self.id = 0
            self.screen_name = '' #jason['screen_name']
            self.followers = 0
            self.followees = 0
            self.recent_status = '' #jason['status']['text']
            self.status_time = datetime.datetime.now()
            self.status_count = 0
            self.status_age = self.status_time - self.timestamp
            self.quality = -999
